package com.software.messagecenter.repository;

import com.software.messagecenter.entity.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface MessageRepository extends JpaRepository<Message,String> {

    @Query(value = "SELECT * FROM message\n" +
            "WHERE sender_id = ?1\n" +
            "OR receiver_id = ?1 ORDER BY send_time DESC",nativeQuery = true)
    List<Message> findMessagesByUserId(String userId);


    List<Message> findMessagesBySenderIdAndReceiverId(String senderId,String receiverId);

}
